package com.huawei.hms.support.api.push.b.c;

import android.content.Context;
import android.content.Intent;
import com.huawei.hms.support.api.push.b.b.a;
import com.huawei.hms.support.log.HMSLog;

public class d extends Thread {
    private Context a;
    private a b;
    private String c;

    public d(Context context, a aVar, String str) {
        this.a = context;
        this.b = aVar;
        this.c = str;
    }

    private static Intent a(Context context, a aVar) {
        if (aVar == null) {
            return null;
        }
        Intent b = com.huawei.hms.support.api.push.b.d.a.b(context, aVar.o());
        Intent parseUri;
        if (aVar.g() != null) {
            try {
                parseUri = Intent.parseUri(aVar.g(), 0);
                HMSLog.d("PushSelfShowLog", "Intent.parseUri(msg.intentUri, 0)，" + parseUri.toURI());
                if (!com.huawei.hms.support.api.push.b.d.a.a(context, aVar.o(), parseUri).booleanValue()) {
                    parseUri = b;
                }
                return parseUri;
            } catch (Exception e) {
                HMSLog.w("PushSelfShowLog", "intentUri error" + e.toString());
                return b;
            }
        }
        if (aVar.p() != null) {
            parseUri = new Intent(aVar.p());
            if (com.huawei.hms.support.api.push.b.d.a.a(context, aVar.o(), parseUri).booleanValue()) {
                b = parseUri;
            }
        }
        b.setPackage(aVar.o());
        return b;
    }

    public void run() {
        HMSLog.i("PushSelfShowLog", "enter run()");
        try {
            if (a(this.a) && !b(this.a, this.b)) {
                c.a(this.a, this.b, this.c);
            }
        } catch (Exception e) {
            HMSLog.e("PushSelfShowLog", e.toString());
        }
    }

    private boolean a(Context context) {
        if ("cosa".equals(this.b.j())) {
            return b(context);
        }
        return true;
    }

    private boolean b(Context context) {
        return com.huawei.hms.support.api.push.b.d.a.c(context, this.b.o());
    }

    private boolean b(Context context, a aVar) {
        boolean z = false;
        if (!"cosa".equals(aVar.j())) {
            return false;
        }
        Intent a = a(context, aVar);
        if (a == null) {
            HMSLog.d("PushSelfShowLog", "launchCosaApp,intent == null");
            z = true;
        }
        if (com.huawei.hms.support.api.push.b.d.a.a(context, a)) {
            return z;
        }
        HMSLog.i("PushSelfShowLog", "no permission to start activity");
        return true;
    }
}
